package smartq.app;

import java.util.ArrayList;
import java.util.HashMap;

import com.app.smart_q.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class ShowActivity extends Activity  {
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_show);
	
		final myDBClass myDb = new myDBClass(this);
		final ArrayList<HashMap<String, String>> MebmerList = myDb.SelectAllData();   
		
        // listView1
        ListView lisView1 = (ListView)findViewById(R.id.smartq_listview1); 
        
        SimpleAdapter sAdap;
        sAdap = new SimpleAdapter(ShowActivity.this, MebmerList, R.layout.activity_column,
                new String[] {"MemberID", "Name", "Tel"}, new int[] {R.id.Colum_Q, R.id.Colum_Name, R.id.Colum_Time});      
        lisView1.setAdapter(sAdap);
        
        lisView1.setOnItemClickListener(new OnItemClickListener() {
		      public void onItemClick(AdapterView<?> myAdapter, View myView, int position, long mylng) {
		    	   
		    	  	// Show on new activity
	            	Intent newActivity = new Intent(ShowActivity.this,DetailActivity.class);
	            	newActivity.putExtra("MemID", MebmerList.get(position).get("MemberID").toString());
	            	startActivity(newActivity);

		      }       
        });
		   
		
		// btnCancel (Cancel)
        final Button cancel = (Button) findViewById(R.id.btnCancel);
        cancel.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {        	
            	// Open Form Main
            	Intent newActivity = new Intent(ShowActivity.this,MainActivity2.class);
            	startActivity(newActivity);
            }
        });
        
	}
	
    
}

